home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Techy Stuff / Source ƒ / ASM 2.0 ƒ / emit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-15  |  1.8 KB  |  106 lines

  1. #include <stdio.h>
  2. #include "as.h"
  3.  
  4. int     E_total =0;             /* total # bytes for one line           */
  5. char    E_bytes[E_LIMIT] = {0}; /* Emitted held bytes                   */
  6. int     E_pc =0;                /* Pc at beginning of collection        */
  7.  
  8. int     P_force = 0;            /* force listing line to include Old_pc */
  9. int     P_total =0;             /* current number of bytes collected    */
  10. int     P_bytes[P_LIMIT] = {0}; /* Bytes collected for listing          */
  11.  
  12. extern int Pc;
  13. extern int Pass;
  14. extern char Line[];
  15.  
  16. /*
  17.  *      elong --- emit a long to code file
  18.  */
  19. elong(wd)
  20. int wd;
  21. {
  22.     eword(hiword(wd));
  23.     eword(loword(wd));
  24. }
  25.  
  26. /*
  27.  *      eword --- emit a word to code file
  28.  */
  29. eword(wd)
  30. int     wd;
  31. {
  32.     emit(hibyte(wd));
  33.     emit(lobyte(wd));
  34. }
  35.  
  36. /*
  37.  *      emit --- emit a byte to code file
  38.  */
  39. emit(byte)
  40. {
  41.     if(Pass==1)
  42.         Pc++;
  43.     else{
  44.         if(P_total < P_LIMIT)
  45.             P_bytes[P_total++] = byte;
  46.         E_bytes[E_total++] = byte;
  47.         Pc++;
  48.         if(E_total == E_LIMIT)
  49.             f_record();
  50.         }
  51. }
  52.  
  53. /*
  54.  *      f_record --- flush record out in `S1' format
  55.  */
  56. f_record()
  57. {
  58.     if(Pass == 1)
  59.         return;
  60.     if(E_total==0){
  61.         E_pc = Pc;
  62.         return;
  63.         }
  64.     srecdata(E_total,E_pc,E_bytes);
  65.     E_pc = Pc;
  66.     E_total = 0;
  67. }
  68.  
  69. /*
  70.  *      print_line --- pretty print input line
  71.  */
  72. print_line()
  73. {
  74.     int     i;
  75.     register char *ptr;
  76.     extern int Old_pc;
  77.  
  78.     if(P_total || P_force)
  79.         printf("%08x",Old_pc);
  80.     else
  81.         printf("        ");
  82.  
  83.     for(i=0;i<P_total && i<6;i++){
  84.         if((i&1)==0)printf(" ");
  85.         printf("%02x",lobyte(P_bytes[i]));
  86.         }
  87.     for(;i<6;i++)
  88.         if( i&1 )
  89.             printf("  ");
  90.         else
  91.             printf("   ");
  92.     printf(" ");
  93.  
  94.     ptr = Line;
  95.     while( *ptr != '\n' )   /* just echo the line back out */
  96.         putchar(*ptr++);
  97.     for(;i<P_total;i++){
  98.         if( i%6 == 0 )
  99.             printf("\n        ");
  100.         if( (i&1)==0 )printf(" ");
  101.         printf("%02x",lobyte(P_bytes[i]));
  102.         }
  103.     printf("\n");
  104. }
  105.  
  106.